package com.sgb.packers.view.activity;

import android.content.Intent;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.MutableLiveData;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.luck.picture.lib.config.PictureConfig;
import com.sgb.link.router.PathTeam;
import com.sgb.packers.R;
import com.sgb.packers.databinding.PackersActivityJobWorkEditBinding;
import com.sgb.packers.view.fragment.GetJobFragment;
import com.sgb.packers.view.fragment.JobWorkEditFragment;
import com.sgb.packers.viewmodel.JobWorkEditViewModel;
import com.swgk.core.common.base.TeamBaseActivity;

/**
 * @author younghow
 * @date 2021/11/12
 * description:包工编辑界面
 */
@Route(path = PathTeam.JobWorkEditActivity)
public class JobWorkEditActivity extends TeamBaseActivity<JobWorkEditViewModel, PackersActivityJobWorkEditBinding> {

    @Autowired(name = "projectName", desc = "项目名称")
    public String projectName;

    @Autowired(name = "year", desc = "年")
    public int year;

    @Autowired(name = "month", desc = "月")
    public int month;

    @Autowired(name = "day", desc = "日")
    public int day;

    @Autowired(name = "projectNo", desc = "项目的no")
    String projectNo;

    @Autowired(name = "no", desc = "流水的no")
    String no;

    public MutableLiveData<Intent> mIntentLiveData = new MutableLiveData<>();

    @Override
    protected Class<JobWorkEditViewModel> createVM() {
        return JobWorkEditViewModel.class;
    }

    @Override
    protected void initView() {
        mBinding.actionBar.setOnBackClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        ARouter.getInstance().inject(this);
        FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
        fragmentTransaction.add(R.id.rl_work, JobWorkEditFragment.newInstance(projectName, year, month, day, projectNo, no));
        fragmentTransaction.commit();
    }

    @Override
    protected void initData() {

    }

    @Override
    protected int layoutId() {
        return R.layout.packers_activity_job_work_edit;
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, @Nullable @org.jetbrains.annotations.Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            if (requestCode == PictureConfig.CHOOSE_REQUEST) {
                mIntentLiveData.setValue(data);
            }
        }
    }
}